

import { Notification, Message, Loading } from 'element-ui'

import { Commit, Dispatch } from 'vuex';
import { get, defaultsDeep, cloneDeep } from 'lodash'

import { getToolList, addToolProduct, deleteToolProduct } from '@/api/tool'



export interface State {

}

const state: State = {
    toolSearch: {
        drawingNumber: '',
        productName: '',
        state: '',
        page: 1,
        pageSize: 20
    },
    totalToolNum: 0,
    toolProductList: []

};

const getters = {};

const mutations = {
    SET_TOOL_SEARCH(state: any, payload: any) {
        state.toolSearch = payload
    },
    SET_PRODUCT_LIST(state: any, payload: any) {
        state.toolProductList = payload
    },
    SET_TOTAL(state: any, payload: any) {
        state.totalToolNum = payload
    }

};

const actions = {

    //表单数据更新
    COMMIT_TABLE_DATA({ commit, state }: any) {
        let params = state.toolSearch

        getToolList(params).then((resp) => {

            let productList = get(resp, 'data', [])
            commit('SET_PRODUCT_LIST', productList)
        })

    },

    //2-06进入工装产品/查询
    async GET_TOOL_LIST(
        { state, commit, rootState, dispatch }: any,
        payload: any
    ) {

        let resp = await getToolList(payload).catch((err: any) => {
            Notification.error(err)
        })

        if (resp) {
            //   Message.success('请求成功!')
            let productList = get(resp, 'data', [])
            let totalNumber = get(resp, 'total', 0)
            commit('SET_PRODUCT_LIST', productList)
            commit('SET_TOTAL', totalNumber)
            return true
        }
    }

}


export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
};